/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package kivuli.visao.item;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.net.URL;
import javax.swing.ImageIcon;
import kivuli.entidade.Figura;
import kivuli.entidade.Predio;
import kivuli.visao.popup.PopupPredio;

/**
 *
 * @author JULIENA NOBRE SOARES
 */
public class ItemPredio extends ItemDeDesenho {

    private static final URL PATH_IMAGEM
            = ItemDeDesenho.class.getResource("/resources/images/predio.gif");

    private final ImageIcon image;

    public ItemPredio(Predio predio) {
        super(predio);
        image = new ImageIcon(PATH_IMAGEM);
        this.setSize(predio.getComprimento() + 1, predio.getLargura() + 1);
        this.setComponentPopupMenu(new PopupPredio(this));
    }

    @Override
    public void setFigura(Figura figura) {
        super.setFigura(figura);
        if (figura != null && figura instanceof Predio) {
            Predio predio = (Predio) figura;
            this.setSize(predio.getComprimento() + 1,
                    predio.getLargura() + 1);
        }
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Predio predio = (Predio) getFigura();
        setLocation(predio.getX(), predio.getY());
        Graphics2D g2d = (Graphics2D) g.create();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.drawImage(image.getImage(),
                (predio.getComprimento() - (int) (predio.getComprimento() * 0.35)) / 2,
                (predio.getLargura() - (int) (predio.getLargura() * 0.35)) / 2,
                (int) (predio.getComprimento() * 0.35),
                (int) (predio.getLargura() * 0.35), null);
        g2d.draw3DRect(0, 0, predio.getComprimento(), predio.getLargura(), true);
        g2d.dispose();
    }
}
